package com.itheima.weaponhomework;

public class Army {
    private Weapon[] weapons;

    public Army(int len){
        weapons = new Weapon[len];
    }
    public void addWeapon(Weapon weapon) throws AddWeaponException{
        for(int i=0;i<weapons.length;i++){
            if(weapons[i]==null){
                weapons[i]=weapon;
                return;
            }
        }
        throw new AddWeaponException("武器已满！");

    }

    public void shootAll(){
        for (Weapon weapon : weapons) {
            if (weapon instanceof Shootable) {
                Shootable shootable = (Shootable) weapon;
                shootable.shoot();
            }
        }
    }

    public void moveAll(){
        for(Weapon weapon:weapons){
            if(weapon instanceof Moveable){
                Moveable moveable = (Moveable) weapon;
                moveable.move();
            }
        }

    }


}
